package com.yun.algorithmproblem.leetcode;

public class Leetcode1695 {

    public static void main(String[] args) {
        Leetcode1695 obj = new Leetcode1695();
        System.out.println(obj.maximumUniqueSubarray(new int[]{187, 470, 25, 436, 538, 809, 441, 167, 477, 110, 275, 133, 666, 345, 411, 459, 490, 266, 987, 965, 429, 166, 809, 340, 467, 318, 125, 165, 809, 610, 31, 585, 970, 306, 42, 189, 169, 743, 78, 810, 70, 382, 367, 490, 787, 670, 476, 278, 775, 673, 299, 19, 893, 817, 971, 458, 409, 886, 434}));
    }

    public int maximumUniqueSubarray(int[] nums) {
        int[] bucket = new int[10001];
        int max = 0, sum = 0;
        int p = 0, q;
        for (q = 0; q < nums.length; q++) {
            while (bucket[nums[q]] > 0) {
                sum -= nums[p];
                bucket[nums[p]]--;
                p++;
            }
            sum += nums[q];
            max = Math.max(max, sum);
            bucket[nums[q]]++;
        }
        String a = new String("a");
        String b = "a";
        return max;
    }
}
